<?php
/**
 * 运营后台专题活动
 */
namespace Operate\Controller;

use Common\Controller\AdminbaseController;
use Common\Libiary\BaseApiHttp;
use Common\Libiary\CommonBill;
use Common\Libiary\LogEX;
use Common\Libiary\Uploadify;

class SpecialController extends AdminbaseController
{
    public $url = '';
    public $data = [];
    public $arr = [];
    public $page = 1;
    public $type;
    //首页列表
    function main()
    {
        $url = CommonBill::getH5Url() . 'api/operate/special/list';
        $baseApi = new BaseApiHttp();
        $params = $baseApi->build_sparams();
        $this->type = I('get.Type', '', 'intval');
        $params['Type'] = $this->type;
        $ret = $baseApi->http($url, 'POST', $params);
        $this->list = json_decode($ret, true);
        $this->assign('type', $this->type);
        $this->display();
    }

    function getMore()
    {
        $this->url = CommonBill::getH5Url() . 'api/operate/special/list';
        $baseApi = new BaseApiHttp();
        $params = $baseApi->build_sparams();
        $params['Page'] = I('post.Page', 1, 'intval');
        $params['Order'] = I('post.Order', 'desc', 'trim');
        $this->type = I('post.Typeid', '', 'intval');
        $params['Type'] = $this->type;
        $ret = $baseApi->http($this->url, 'POST', $params);
        echo $ret;
        exit;
    }

    public function add()
    {
        $this->display();
    }

    /**
     * 获取商品信息
     */
    function getShopInfo()
    {
        $shopInfo = I('post._actShopid');
        $baseApi = new BaseApiHttp();
        $url = CommonBill::getServiceUrl().'searchlistv2';
        if (is_numeric($shopInfo)) {
            $data = [
                'shopid' => $shopInfo,
                'entitystore' => 2
            ];
        } else {
            $data = [
                'kw' => $shopInfo,
                'entitystore' => 2
            ];
        }
        $ret = $baseApi->https($url, 'POST', $data);
        echo $ret;
        exit;

    }

    //获得是否开通排队和预约功能
    function getShopService()
    {
        $shopid = I('post.shopid', '', 'intval');
        $baseApi = new BaseApiHttp();
        $url = CommonBill::getServiceUrl().'searchlistv2';
        $data = [
            'shopid' => $shopid,
            'entitystore' => 2
        ];
        $ret = $baseApi->https($url, 'POST', $data);
        LogEX::i('是否开通预约功能'.$shopid,['data'=>$ret],__FILE__,__LINE__);
        $result = json_decode($ret, true);
        if ($result['code'] == 0) {
            return $this->ajaxReturn($result['data']['list'][0]);
        }
    }

    public function uploadify()
    {
        $upload = new Uploadify();
        $arr = $upload->uploadify($_FILES['coverImg'], 1);
        $data = [
            'res' => 0,
            'info' => $arr
        ];
        $this->ajaxReturn($data);
    }

    //添加出来

    public function addHandle()
    {
        //加密请求
        $baseApi = new BaseApiHttp();
        $data = $baseApi->build_sparams();
        $url = CommonBill::getH5Url() . 'api/operate/special/addhandel';
        $data['ActName'] = I('post.ActName');  //活动标题
        $data['ShopImg'] = I('post.ShopImg');   //活动图片
        $data['Shop'] = I('post.Shop');   //大图
        $data['linkurl'] = I('post.linkurl');  //小图
        $data['bookdate'] = I('post.bookdate');  //预约类型
        $data['moreShop'] = I('post.moreShop');  //跳转类型
        $ret = $baseApi->https($url, 'POST', $data);
        LogEX::i('专题添加处理',[$url,$data,$ret],__FILE__,__LINE__);
        echo $ret;
        exit;
    }

    /**
     * 查看
     */
    public function view()
    {
        //查出活动及分店信息
        $baseApi = new BaseApiHttp();
        $data = $baseApi->build_sparams();
        $url = CommonBill::getH5Url() . 'api/operate/special/view';
        $data['Id'] = I('get.id');  //专题活动ID
        $ret = $baseApi->https($url, 'POST', $data);
        LogEX::i('查看专题活动',[$url,$data,$ret],__FILE__,__LINE__);
        $this->list = json_decode($ret, true);
        $this->display();
    }

    /**
     * 编辑活动信息
     */
    public function editActivityInfo()
    {
        $baseApi = new BaseApiHttp();
        $data = $baseApi->build_sparams();
        $url = CommonBill::getH5Url() . 'api/operate/special/edit';
        $data['Id'] = I('post.id');
        $data['ActName'] = I('post.actName');
        $data['Img'] = I('post.img');
        $data['bookdate'] = I('post.bookdate');
        $data['moreShop'] = I('post.moreShop');
        $ret = $baseApi->https($url, 'POST', $data);
        LogEX::i('编辑活动信息',[$url,$data,$ret],__FILE__,__LINE__);
        echo $ret;
        exit;
    }

    /**
     * 详情页添加店铺
     */
    function addBusinessinfo()
    {
        //加密请求
        $baseApi = new BaseApiHttp();
        $data = $baseApi->build_sparams();
        $url = CommonBill::getH5Url() . 'api/operate/special/addbusiness';
        $data['ShopCityId'] = I('post._shopCityId');   //城市id
        $data['ShopName'] = I('post._businessName');   //店铺名称
        $data['ShopPic'] = I('post._businessImg');   //店铺图片
        $data['ShopDesc'] = I('post._businessDesc');   //店铺描述
        $data['Businessid'] = I('post._businessid');   //店铺id
        $data['ShopTitle'] = I('post._businessTitle');   //店铺标题
        $data['ShopId'] = I('post._shopid');   //活动id
        $data['businessTag'] = I('post.businessTag');   //标签
        $data['shopType'] = I('post.shopType');   //分类
        $data['shopSort'] = I('post.shopSort');   //排序
        $ret = $baseApi->https($url, 'POST', $data);
        LogEX::i('详情页添加店铺',[$url,'data'=>$data,$ret],__FILE__,__LINE__);
        echo $ret;
        exit;
    }

    /**
     * 编辑商家
     */
    public function editBusiness()
    {
        //加密请求
        $baseApi = new BaseApiHttp();
        $data = $baseApi->build_sparams();
        $url = CommonBill::getH5Url() . 'api/operate/special/editbusiness';
        $data['Id'] = I('post._id');
        $ret = $baseApi->https($url, 'POST', $data);
        $this->list = json_decode($ret, true);
        LogEX::i('编辑商家',[$url,$data,$this->list],__FILE__,__LINE__);
        $this->ajaxReturn($this->list);
    }

    /**
     * 保存修改后的商家
     */
    public function saveEditBusiness()
    {
        //加密请求
        $baseApi = new BaseApiHttp();
        $data = $baseApi->build_sparams();
        $url = CommonBill::getH5Url() . 'api/operate/special/saveeditbusiness';
        $data['Id'] = I('post._businessid');
        $data['BusinessTitle'] = I('post._businessTitle');
        $data['BusinessDesc'] = I('post._businessDesc');
        $data['BusinessPic'] = I('post._businessPic');
        $data['Actid'] = I('post._actId');
        $data['Sort'] = I('post.sort');
        $data['ShopTag'] = I('post.shopTag');
        $ret = $baseApi->https($url, 'POST', $data);
        LogEX::i('保存修改后的商家',[$url,$data,$ret],__FILE__,__LINE__);
        echo $ret;
        exit;
    }

    /**
     *保存推荐专题
     */
    function addSpecialLink()
    {
        //加密请求
        $baseApi = new BaseApiHttp();
        $data = $baseApi->build_sparams();
        $url = CommonBill::getH5Url() . 'api/operate/special/savelink';
        $data['linkUrl'] = I('post.link');
        $data['Actid'] = I('post.Actid');
        $ret = $baseApi->https($url, 'POST', $data);
        LogEX::i('保存推荐专题',[$url,$data,$ret],__FILE__,__LINE__);
        echo $ret;
        exit;
    }

    /**
     * 排序
     */
    function saveSortBusiness()
    {
        //加密请求
        $baseApi = new BaseApiHttp();
        $data = $baseApi->build_sparams();
        $url = CommonBill::getH5Url() . 'api/operate/special/savesortbusiness';
        $data['Id'] = I('post._bsid');
        $data['Sort'] = I('post._sort');
        $data['Type'] = I('post._type');
        $ret = $baseApi->https($url, 'POST', $data);
        $this->list = json_decode($ret, true);
        echo $this->list;
        exit;
    }

    /**
     * 查看预览
     */
    function visit()
    {

        $baseApi = new BaseApiHttp();
        $data = $baseApi->build_sparams();
        $url = CommonBill::getH5Url() . 'api/operate/special/viewinfo';
        $data['Id'] = I('get.ID');  //专题活动ID
        $ret = $baseApi->https($url, 'POST', $data);
        $this->list = json_decode($ret, true);
        $this->display();
    }

    /**
     * 删除
     */
    function delBusiness()
    {
        $baseApi = new BaseApiHttp();
        $data = $baseApi->build_sparams();
        $url = CommonBill::getH5Url() . 'api/operate/special/delbusiness';
        $data['Id'] = I('post.id');
        $ret = $baseApi->https($url, 'POST', $data);
        LogEX::i('删除商家信息',[$url,$data,$ret],__FILE__,__LINE__);
        echo $ret;
        exit;
    }

    /**
     *
     */
    public function uploadshoppic()
    {
        $upload = new Uploadify();
        $arr = $upload->uploadify($_FILES['coverImg'], 1);
        $data = [
            'res' => 0,
            'info' => $arr
        ];
        $this->ajaxReturn($data);
    }

    /**
     * 上传大图
     */
    function uploadBigImg()
    {
        $upload = new Uploadify();
        $arr = $upload->uploadify($_FILES['coverBigImg'], 1);
        $data = [
            'res' => 0,
            'info' => $arr
        ];
        $this->ajaxReturn($data);
    }

    /**
     * 上传小图
     */
    function uploadSmallImg()
    {
        $upload = new Uploadify();
        $arr = $upload->uploadify($_FILES['coverSmallImg'], 1);
        $data = [
            'res' => 0,
            'info' => $arr
        ];
        $this->ajaxReturn($data);
    }

}